# 27. 内存冷热标记

27

const readline = require('readline');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});
let lines = [];

rl.on('line', function(line) {
    lines.push(line);
    if (lines.length === 3) {
        const pageAccessCount = parseInt(lines[0].trim(), 10);
        const pageAccessSeq = lines[1].trim().split(' ').map(Number);
        const hotThreshold = parseInt(lines[2], 10);
        let obj = {};
        for(let v of pageAccessSeq) {
            obj[v] = obj[v] ? (obj[v] + 1) : 1;
        }
        const hotPages = [];
        for(let i in obj) {
            if (obj[i] >=  hotThreshold) {
                hotPages.push(parseInt(i));
            }
        }
        console.log(hotPages.length);
        if (hotPages.length) {
            hotPages.sort((a, b) => a-b);
            hotPages.forEach(page => console.log(page));
        }
    }
})

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31